/*
 * acm2480.c
 *
 *  Created on: 6 Apr 2010
 *      Author: xuxu
 */

#include<stdio.h>
int main()
{
	int window[11][4];
	int n,count,judge;
	int i,j;
	int x,y;
	int bo;
	while(scanf("%d",&n)&&n)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d%d",&window[i][0],&window[i][1],&window[i][2],&window[i][3]);
		}
		scanf("%d",&judge);
		for(i=0;i<judge;i++)
		{
			scanf("%d%d",&x,&y);
			bo=0;
			for(j=n-1;j>=0;j--)
			{
				if((x>=window[j][0]&&x<=window[j][2])&&(y>=window[j][1]&&y<=window[j][3]))
				{
					printf("%d\n",j);
					bo=1;
					break;
				}
			}
			if(0==bo)
				printf("-1\n");
		}
	}
	return 0;
}
